-
Notifications
You must be signed in to change notification settings - Fork 235
Add function level trace #3633
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Add function level trace #3633
Conversation
8a25e67
to
19afecd
Compare
d88921d
to
546c8a7
Compare
commit-id:d194aae4 --- **Stack**: - #3634 - #3633 - #3621 - #3620 ⬅⚠️ *Part of a stack created by [spr](https://github.com/ejoffe/spr). Do not merge manually using the UI - doing so may have unexpected results.*
pub value: FunctionName, | ||
pub children: Vec<FunctionNode>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Imo it's reasonable to make it private and expose with getters if needed.
crates/debugging/Cargo.toml
Outdated
serde_json.workspace = true | ||
starknet-types-core.workspace = true | ||
starknet.workspace = true | ||
starknet_api.workspace = true | ||
thiserror.workspace = true | ||
thiserror.workspace = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Newline 😅
19afecd
to
df6c5f0
Compare
546c8a7
to
2ba7a7c
Compare
|
||
/// Builds a [`FunctionTrace`] from the given stacks of function names. | ||
fn build_function_trace(stacks: Vec<Vec<FunctionName>>) -> FunctionTrace { | ||
let mut dummy_root = FunctionNode::new(FunctionName::NonInlined("root".to_string())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: dummy_root
works, but placeholder_root
might better convey that it's a temporary node for building the tree:
let mut dummy_root = FunctionNode::new(FunctionName::NonInlined("root".to_string())); | |
let mut placeholder_root = FunctionNode::new(FunctionName::NonInlined("root".to_string())); |
commit-id:6dc6b503 --- **Stack**: - #3634 - #3633 - #3621 ⬅⚠️ *Part of a stack created by [spr](https://github.com/ejoffe/spr). Do not merge manually using the UI - doing so may have unexpected results.*
df6c5f0
to
6bc9621
Compare
#[derive(Debug, Clone, Hash, Eq, PartialEq)] | ||
pub enum FunctionName { | ||
NonInlined(String), | ||
// TODO: Add inlined variant in next PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotta love stacks 🙏 🙏 🙏
Regex::new(r"\[expr\d*]") | ||
.expect("Failed to create regex for normalizing loop function names") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we have the regex as a const/static and reuse it instead of creating it multiple times?
/// Remove parameters from monomorphised Cairo generics e.g. `<felt252>`. | ||
fn remove_monomorphization_suffix(function_name: &str) -> String { | ||
static RE_MONOMORPHIZATION: LazyLock<Regex> = LazyLock::new(|| { | ||
Regex::new(r"::<.*>") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
if let Some(child) = self.children.iter_mut().find(|c| c.value == next) { | ||
child.add_path_recursive(iter); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I get it, why do we have this logic?
/// Enters a new function call by updating the stack with the new call stack. | ||
/// It saves the current stack length to allow returning to it later. | ||
/// | ||
/// The New call stack is expected to be a prefix of the current stack. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's ensuring that? Only the user contract?
Would checking that be too expensive?
} | ||
|
||
/// Exits the current function call by truncating the stack to the previous length. | ||
/// If there is no previous length, it does nothing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is that? Shouldn't it truncate the stack entirely in this case?
let empty_or_different_function = self.stack.last().is_none_or(|current_function| { | ||
current_function.function_name() != function_name.function_name() | ||
}); | ||
|
||
if empty_or_different_function { | ||
stack.push(function_name); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So basically it appends to new function to the stack if it's not already present as last?
|
||
let program = &program_artifact.program; | ||
|
||
let sierra_program_registry = ProgramRegistry::<CoreType, CoreLibfunc>::new(program) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of these objects, like ProgramRegistry
we already create during forge runtime. I wonder if there would be any significant benefit in trying to reuse them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same goes for constructing trace
} | ||
|
||
impl NodeDisplay for FunctionNode { | ||
const TAG: &'static str = "inlined"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are they always inlined?
6bc9621
to
2d73b2a
Compare
commit-id:3a7228bd
2d73b2a
to
b329d45
Compare
Stack:
NodeDisplay
const TAG
tofn tag(&self)
#3657